package io.buffered;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

//乱序文章，重新排序输出在控制台
public class Demo07SortText {
    private static List<String> list = new ArrayList<>();

    public static void main(String[] args) throws Exception {
        File file = new File("F://Test//T4//无序文件.txt");
        add(file);
        sortPrint();
    }

    private static void add(File file) throws Exception {
        BufferedReader br = new BufferedReader(new FileReader(file));
        String s;
        while ((s = br.readLine()) != null) {
            if (s.trim().length() != 0)
                list.add(s);
        }
    }

    private static void sortPrint() {
        String[] strings = list.toArray(new String[list.size()]);
        Arrays.sort(strings);
        for (String string : strings) {
            System.out.println(string);
        }
    }

}
